package com.voc.im.present;

import com.voc.im.view.IAccount;
import com.voc.im.xmpp.IMConnection;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
import javafx.concurrent.Task;

import java.util.concurrent.Callable;

public class AccountPresenter extends BasePresenter<IAccount> {

    public AccountPresenter(IAccount view) {
        super(view);
    }

    public void login(String username, String password) {
        if (username.isEmpty()) {

        }
        if (password.isEmpty()) {

        }
        if (username.isEmpty() || password.isEmpty()) {
            return;
        }

        Task<Boolean> integerTask = new Task<Boolean>() {
            @Override
            protected Boolean call() throws Exception {
                return IMConnection.getInstance().connectLogin(username, password);
            }
        };
        new Thread(integerTask).start();

        integerTask.exceptionProperty().addListener((observable, oldValue, newValue) -> {
            System.out.println(newValue.getMessage());
        });
        integerTask.valueProperty().addListener((observable, oldValue, newValue) -> {

        });
    }
}
